package com.inspur.gs.sbssdl.sbyxgl.djjl.djjl.front.newdjbzpz_frm.voactions;
import com.inspur.edp.bef.api.lcp.ILcpFactory;
import com.inspur.edp.bef.api.lcp.IStandardLcp;
import com.inspur.edp.bef.api.services.IBefSessionManager;
import com.inspur.edp.bff.spi.*;
import com.inspur.edp.bef.api.action.*;
import com.inspur.edp.cef.entity.changeset.ModifyChangeDetail;
import com.inspur.edp.cef.entity.entity.IEntityData;
import com.inspur.edp.cef.entity.entity.IEntityDataCollection;
import io.iec.edp.caf.commons.utils.SpringBeanUtils;

import java.util.ArrayList;

public class deleteChangeVOAction extends AbstractFSAction<VoidActionResult> {

	private String mainid;
	private String[] ids;
	public deleteChangeVOAction(String mainid,String[] ids) {

		this.mainid = mainid;
		this.ids = ids;
	}

	private static String sbtzCfg = "efd56b39-0e8d-4441-9fa1-2b019b6fd862";
	@Override
	public void execute() {
		ArrayList<String> nodeCodes = new ArrayList<>();
		//hierachyIdList包含主表数据的唯一标识
		ArrayList<String> hierachyIdList = new ArrayList<>();
		hierachyIdList.add(mainid);
		//ids包含要删除的从表数据的唯一标识
		ArrayList<String> childids = new ArrayList<>();
		for (String id : ids) {
			childids.add(id);
		}
		SpringBeanUtils.getBean(IBefSessionManager.class).createSession();
		try {
			ILcpFactory iLcpFactory = SpringBeanUtils.getBean(ILcpFactory.class);
			//设备台账的变更
			IStandardLcp lcp = iLcpFactory.createLcpByBEId(sbtzCfg);
			IEntityData data = lcp.retrieve(mainid).getData();
			IEntityDataCollection bybzmx = data.getChilds().get("djbz");
			ModifyChangeDetail curChange = new ModifyChangeDetail(mainid);
			if (bybzmx.size()==ids.length){
				curChange.putItem("gjp", false);
			}
			nodeCodes.add("djbz");//真实子表编号
			lcp.deleteChild(nodeCodes,hierachyIdList,childids);
			lcp.modify(curChange);
			lcp.save();
		} finally {
			SpringBeanUtils.getBean(IBefSessionManager.class).closeCurrentSession();
		}
	}
}
